package com.hctg.forced2sleep.adapter;

import android.widget.TextView;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.hctg.forced2sleep.R;

/**
 * description: 描述
 * company    :
 *
 * @author : ldf
 * date       : 2025/1/3 on 10
 * @version 1.0
 */
public class LimitEditAdapter extends BaseQuickAdapter<String, BaseViewHolder> {

    private int selectedPos = 0;

    public LimitEditAdapter() {
        super(R.layout.item_quit_money);
        setOnItemClickListener((adapter, view, position) -> {
            if (position != selectedPos) {
                int oldPos = selectedPos;
                selectedPos = position;
                notifyItemChanged(oldPos);
                notifyItemChanged(position);
            }
        });
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, String item) {
        int pos = holder.getAbsoluteAdapterPosition();
        TextView tv = holder.getView(R.id.tv_name);
        tv.setText(item);
        tv.setSelected(pos == selectedPos);
    }
}
